<%@page import="com.situ.web.vo.StudentBanjiVO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.situ.web.entity.Student"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
<style type="text/css">
	.right{
		float: right;
		height: 40px;
		
	}
</style>
<%@ include file="/header.jsp"%>
</head>
<body>
	<table class="layui-hide" id="test"></table>
	
	<div style="width: 1000px; margin: 10px auto;">
	<%-- ${list} --%>
		<!-- <a href="/Java202007Web/student_insert.jsp">添加</a> -->
		<a href="/Java202007Web/student?method=selectBanjiName" class="btn btn-default btn-lg active right" role="button">添加</a>
		<form action="<%=request.getContextPath()%>/student?method=selectName" method="post">
			<input type="text" name="selectName" style="height: 36px;"/>
			<input type="submit" value="搜索"/ style="height: 36px; width: 50px;">
		</form>
		<table class="table table-hover table-bordered">
			<tr class="warning">
				<td>ID</td>
				<td>名字</td>
				<td>年龄</td>
				<td>性别</td>
				<td>班级名</td>
				<td>课程名</td>
				<td>学分</td>
				<td>修改</td>
				<td>删除</td>
			</tr>
			<% // 这里可以嵌套java代码
				// request是jsp页面的内置对象，我们可以直接使用
				// req.setAttribute("list", list);
				// 从request里面拿出list数据
				List<StudentBanjiVO> list = (ArrayList<StudentBanjiVO>)request.getAttribute("list");
				for	 (StudentBanjiVO student :list) {
					// 每遍历一个student就在table中打印一行数据tr
			%>
				<tr>
					<td><%=student.getId()%></td>
					<td><%=student.getName()%></td>
					<td><%=student.getAge()%></td>
					<td><%=student.getGender()%></td>
					<td><%=student.getBanjiName()%></td>
					<td><%=student.getCourseName()%></td>
					<td><%=student.getCredit()%></td>
					<%-- <td><a href="/Java202007Web/student?method=delete&id=<%=student.getId()%>">删除</a></td> --%>
					<td><a href="/Java202007Web/student?method=selectId&id=<%=student.getId()%>">修改</a></td>
					<td><a href="javascript:void(0)" onclick="deleteId(<%=student.getId()%>)">删除</a></td>
				</tr>
		
			<%
				}
			%>
		</table>
	</div>
		
	<script type="text/javascript">
		layui.use('table', function(){
		  var table = layui.table;
		  
		  table.render({
		    elem: '#test'
		    ,url:'${path}/student?method=selectAll'
		    ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
		    ,cols: [[
		      {field:'id', width:80, title: 'ID', sort: true}
		      ,{field:'username', width:80, title: '用户名'}
		      ,{field:'sex', width:80, title: '性别', sort: true}
		      ,{field:'city', width:80, title: '城市'}
		      ,{field:'sign', title: '签名', width: '30%', minWidth: 100} //minWidth：局部定义当前单元格的最小宽度，layui 2.2.1 新增
		      ,{field:'experience', title: '积分', sort: true}
		      ,{field:'score', title: '评分', sort: true}
		      ,{field:'classify', title: '职业'}
		      ,{field:'wealth', width:137, title: '财富', sort: true}
		    ]]
		  });
		});
	
		function deleteId(id){
			/* var isDelete = confirm('您确定要删除吗？');
			if (isDelete) {
				location.href = '/Java202007Web/student?method=delete&id=' + id;
			} */
			// mylayer.confirm('您确定要删除吗？', '${pageContext.request.contextPath}/student?method=delete&id=' + id);
			layer.confirm(
				'您确定要删除吗？',
				{icon : 3},
				function(index){
					$.post(
						'${pageContext.request.contextPath}/student?method=delete',
						{'id' : id},
						function(jsonObj){
							if(jsonObj.isSuccess){
								mylayer.successUrl(jsonObj.msg, '${path}/student?method=selectAll');
								
							}else{
								mylayer.errorMsg(jsonObj.msg);
							}
						},
						'json'
					);
					layer.close(index);
				}
			);
		}
	</script>
</body>
</html>